/**
 * 
 */
(function($) {
	
    function getSelectedText() {
    	var node = window.document.createElement('span');
		if (window.getSelection) {
			// This technique is the most likely to be standardized.
			// getSelection() returns a Selection object, which we do not
			// document.
			var range = window.getSelection().getRangeAt(0);
			var keyword = window.getSelection().toString();
			if($.trim(keyword) == '')return;
			$(node).css({border: '2px solid red'}).addClass('callxbox').text(keyword);
			range.insertNode(node);
//			return window.getSelection().toString();
		} else if (document.getSelection) {
			// This is an older, simpler technique that returns a string
			var range = document.getSelection();
			$.log(range.cloneContents().childNodes);
			var keyword = document.getSelection();
//			return document.getSelection();
		} else if (document.selection) {
			// This is the IE-specific technique.
			// We do not document the IE selection property or TextRange
			// objects.
			var range = document.selection.createRange();
			$.log(range.cloneContents().childNodes);
			var keyword = document.selection.createRange().text;
//			return document.selection.createRange().text;
		}
		range.deleteContents();
		$(node).css({border: '2px solid red'}).addClass('callxbox').text(keyword);
		range.insertNode(node);
		return {keyword: keyword, node: node};
	}
	    

    function getTextFieldSelection(e) {
		if (e.selectionStart != undefined && e.selectionEnd != undefined) {
			var start = e.selectionStart;
			var end = e.selectionEnd;
			return e.value.substring(start, end);
		} else
			return ""; // Not supported on this browser   
	}


	$.getTextFieldSelection = getTextFieldSelection;
	$.getSelectedText = getSelectedText;
})(jQuery);